package servlets;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.RemitoVO;

import cliente.BDelegate;

/**
 * Servlet implementation class MostrarVentaXML
 */
public class MostrarVentaXML extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MostrarVentaXML() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		BDelegate bussinessDelegate = new BDelegate();
		String archivoXML = request.getParameter("archivoXML");
		
		File file = new File(archivoXML);
		InputStream fin = new FileInputStream(file);		

		BufferedReader myInput = new BufferedReader(new InputStreamReader(fin));
		StringBuffer myInputString = new StringBuffer();
		
		while (myInput.ready()) {  
			myInputString.append(myInput.readLine());
		}
		
		String remito = bussinessDelegate.solicitarVenta(myInputString.toString());
		
		
		request.setAttribute("archivoXML", myInputString.toString());
		request.setAttribute("remito", remito);
		
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("XMLDetalleVenta.jsp");
		requestDispatcher.forward(request, response);
		
	}

}
